import { dataQueryAxios, datashopAxios } from '@/utils/request.ts'

export const favorFilterList = (params: { keywords?: string; release_item_id?: string; page: number; page_size: number }) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/favorites/filters`,
    method: 'get',
    params
  })
}

export const favorDataRows = () => {
  return dataQueryAxios({
    url: '/api/data-query/v1/favorites/data/items-count',
    method: 'get'
  })
}

export const deleteFavorFilter = (id: string) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/favorites/filters/${id}`,
    method: 'delete'
  })
}
export const deleteFavorData = (release_item_id: string, data_id: string) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/favorites/data/${release_item_id}/${data_id}`,
    method: 'delete'
  })
}
export const deleteFavorCompany = (company_id: string) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/favorites/companies/${company_id}`,
    method: 'delete'
  })
}

export const favorCompanyList = (params: { page: number; page_size: number }) => {
  return dataQueryAxios({
    url: '/api/data-query/v1/favorites/companies',
    method: 'get',
    params
  })
}

export const favorDataList = (
  release_item_id: string,
  params: {
    keywords?: string
    page: number
    page_size: number
  }
) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/favorites/data/${release_item_id}`,
    method: 'get',
    params
  })
}

export const getTableColumns = (id: string) => {
  return datashopAxios({
    url: `/api/datashop/v4/data-item-products/${id}/columns`,
    method: 'get',
    params: {
      page: 1,
      page_size: 199
    }
  }).then((res) => res.items)
}

export const editFavorFilterName = (id: string, data: { name: string }) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/favorites/filters/${id}`,
    method: 'patch',
    data
  })
}

type exportAllStruct = {
  columns: Array<{ field: string; name: string }>
  filename: string
}

export const exportFavorData = (release_item_id: string, data: exportAllStruct) => {
  return dataQueryAxios({
    url: `/api/data-query/v1/favorites/data/${release_item_id}:export`,
    method: 'post',
    data
  })
}

export const exportFavorCompany = (data: exportAllStruct) => {
  return dataQueryAxios({
    url: '/api/data-query/v1/favorites/companies:export',
    method: 'post',
    data
  })
}
